package com.huitu.whht.base.core.api.geo.irr;

import com.huitu.api.rest.AbstractApiResource;
import com.huitu.commons.PageUtils;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiResource;
import com.huitu.whht.api.core.common.annotations.SzyCoreApiService;
import com.huitu.whht.api.core.common.response.ApiResultBuilder;
import com.huitu.whht.base.core.api.geo.irr.entities.GeoIrrQo;
import com.huitu.whht.base.core.api.geo.irr.service.IGeoIrrCoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

@Component
@SzyCoreApiResource
@Path("geo/irr")
public class GeoIrrCoreResource extends AbstractApiResource {

    private static final Logger logger = LoggerFactory.getLogger(GeoIrrCoreResource.class);

    private static final String UUID = "9be8540b-5321-4668-8a6c-74c39370c192";

    @Autowired
    @SzyCoreApiService
    private IGeoIrrCoreService geoIrrCoreService;

    @Override
    public String getUUID() {
        return UUID;
    }

    /**
     * @api {get} geo/irr/{irrCd:\\w{12}} [R]根据主键查询
     * @apiDescription 根据主键查询GEO_IRR_5T灌区空间信息数据
     * @apiName select by primary key
     * @apiGroup GEO_S02_0019-灌区空间信息
     * @apiVersion 1.0.0
     * @apiSampleRequest geo/irr/420116000058
     * @apiParam {String}         irrCd              【必须】灌区代码
     * @apiSuccess {String}         irrCd              灌区代码
     * @apiSuccess {String}         irrNm              灌区名称
     * @apiSuccess {String}         lgtd               经度
     * @apiSuccess {String}         lttd               纬度
     * @apiSuccess {String}         shape              空间信息
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": {
     * "irrCd": "420116000058",
     * "irrNm": "滠水橡胶坝灌区",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)",
     * "rowId": 1
     * }
     * }
     * @apiUse exceptions
     */
    @GET
    @Path("{irrCd:\\w{12}}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectByPrimaryKey(@PathParam("irrCd") String irrCd) {
        logger.info("根据主键查询 灌区空间信息,参数 irrCd:{}", irrCd);
        return Response.ok(ApiResultBuilder.create(this, geoIrrCoreService.selectByPrimaryKey(irrCd))).build();
    }

    /**
     * @api {post} geo/irr/list [R]根据条件查询(含空间信息)
     * @apiDescription 根据条件查询GEO_WIU_5TGEO_IRR_5T灌区空间信息数据(含空间信息)
     * @apiName select by filter
     * @apiGroup GEO_S02_0019-灌区空间信息
     * @apiVersion 1.0.0
     * @apiSampleRequest geo/irr/list
     * @apiParam {List(String)}   irrCdList          (数组)灌区代码
     * @apiParam {String}         irrCd              灌区代码
     * @apiParam {String}         irrNm              灌区名称
     * @apiParam {List(String)}   irrTpList          (数组)灌区水源类型
     * @apiParam {List(String)}   irrScalList        (数组)灌区规模
     * @apiParam {Double}         desIrrAMin         (最小)设计灌溉面积
     * @apiParam {Double}         desIrrAMax         (最大)设计灌溉面积
     * @apiParam {Double}         fieldIrrAMin       (最小)其中耕地灌溉面积
     * @apiParam {Double}         fieldIrrAMax       (最大)其中耕地灌溉面积
     * @apiParam {List(String)}   runCondList        (数组)运行状况
     * @apiParam {List(String)}   engManCdList       (数组)管理单位代码
     * @apiParam {String}         engManCd           管理单位代码
     * @apiParam {Date}           tsBgTm             (开始时间)时间戳
     * @apiParam {Date}           tsEdTm             (结束时间)时间戳
     * @apiParam {String}         nt                 备注
     * @apiParam {List(String)}   irrStDtList        (数组)灌溉起始月
     * @apiParam {List(String)}   irrEndDtList       (数组)灌溉结束月
     * @apiParam {List(String)}   intTpList          (数组)引水类型
     * @apiParam {Double}         effIrrAMin         (最小)有效灌溉面积
     * @apiParam {Double}         effIrrAMax         (最大)有效灌溉面积
     * @apiParam {Date}           staDtBgTm          (开始时间)开工日期
     * @apiParam {Date}           staDtEdTm          (结束时间)开工日期
     * @apiParam {Date}           comDtBgTm          (开始时间)建成日期
     * @apiParam {Date}           comDtEdTm          (结束时间)建成日期
     * @apiSuccess {String}         irrCd             取用水户代码
     * @apiSuccess {String}         irrNm             取用水户名称
     * @apiSuccess {String}         lgtd              经度
     * @apiSuccess {String}         lttd              纬度
     * @apiSuccess {String}         shape             空间信息
     * @apiSuccessExample 请求成功:
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "irrCd": "420116000058",
     * "irrNm": "滠水橡胶坝灌区",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)"
     * },
     * {
     * "irrCd": "420116000044",
     * "irrNm": "滠口南湖村灌区",
     * "lgtd": 113.093125,
     * "lttd": 29.5690055555556,
     * "shape": "POINT (113.093125 29.5690055555556)"
     * }]
     * }
     * @apiSuccessExample 分页请求:
     * request header: Rang={max=50;size=50;field=TS DESC}
     * HTTP/1.1 200 OK
     * {
     * "result": [{
     * "irrCd": "420116000058",
     * "irrNm": "滠水橡胶坝灌区",
     * "lgtd": 114.433288888889,
     * "lttd": 30.6326805555556,
     * "shape": "POINT (114.433288888889 30.6326805555556)",
     * "rowId": 1
     * },
     * {
     * "irrCd": "420116000044",
     * "irrNm": "滠口南湖村灌区",
     * "lgtd": 113.093125,
     * "lttd": 29.5690055555556,
     * "shape": "POINT (113.093125 29.5690055555556)",
     * "rowId": 2
     * }],
     * "paging": {
     * "count": 3,
     * "total": 120,
     * "finale": false,
     * "index": 1
     * }
     * }
     * @apiUse header_rang
     * @apiUse exceptions
     */
    @POST
    @Path("list")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response selectList(GeoIrrQo filter){
        PageUtils.startPageFromRang();
        logger.info("根据条件查询 地表水水源地空间信息，参数 GeoIrrQo:{}",filter);
        return Response.ok(ApiResultBuilder.create(this,geoIrrCoreService.selectList(filter))).build();
    }
}
